<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: lib/score/ensent.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: lib/score/ensent.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * 用于解析英文句子评分结果&lt;br>
 *
 * @module ChiVoxSDK/score
 * @author Don Li &lt;kai.li@chivox.com>
 * @licence
 * Copyright (c) 2017 - 2020 ChiVox Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /**
 * 英文句子里的Word评分结果。
 */
class Word {
    constructor(data) { this.data = data; }
    getChar() { return this.data.char; }
    getDur() { return this.data.dur; }
    getFluency() { return this.data.fluency; }
    getStressRef() { return this.data.stressref; }
    getStressScore() { return this.data.stressscore; }
    getToneRef() { return this.data.toneref; }
    getToneScore() { return this.data.tonescore; }
    getLiaison() { return this.data.liaison; }
    getScore() { return this.data.score; }
}

 /**
 * 英文句子评分结果。
 */
class EnSentScore {
    constructor(data) { this.data = data; }

    getParams() { return this.data.params; }
    getRecordId() { return this.data.recordId; }
    getAudioUrl() { return this.data.audioUrl; }
    getRank() { return this.data.result.rank; }
    getOverall() { return this.data.result.overall; }
    getPron() { return this.data.result.pron; }
    getIntegrity() { return this.data.result.integrity; }
    getAccuracy() { return this.data.result.accuracy; }
    getFluency() { return this.data.result.fluency.overall; }
    getRhythm() { return this.data.result.rhythm.overall; }

    getWordSize() {
        if (typeof this.data.result["chars"] != "undefined" &amp;&amp; this.data.result["chars"].length > 0) {
            return this.data.result["chars"].length;
        } else {
            if (typeof this.data.result["details"] != "undefined" &amp;&amp; this.data.result["details"].length > 0) {
                return this.data.result["details"].length;
            } else {
                return 0;
            }
        }
    }

    getWord(i) {
        if (typeof this.data.result["chars"] != "undefined" &amp;&amp; this.data.result["chars"].length > 0) {
            var charI = {
                "char": "",
                "dur": 0,
                "fluency": 0,
                "score": 0,
                "senseref": 0,
                "sensescore": 0,
                "stressref": 0,
                "stressscore": 0,
                "toneref": 0,
                "tonescore": 0,
                "liaison": 0
            };

            var passLength = 0;
            for (var j = 0; j &lt; i; j++) {
                passLength += this.data.result["chars"][j].normalize.length;
            }

            var cl = this.data.result["chars"][i];
            charI["char"] = cl["char"];
            for (var num = 0; num &lt; cl.normalize.length; num++) {
                var obj = this.data.result["details"][passLength + num];
                charI["dur"] += obj["dur"];
                charI["fluency"] += obj["fluency"];
                charI["score"] += obj["score"];
                charI["senseref"] += obj["senseref"];
                charI["sensescore"] += obj["sensescore"];
                charI["stressref"] += obj["stressref"];
                charI["stressscore"] += obj["stressscore"];
                charI["toneref"] += obj["toneref"];
                charI["tonescore"] += obj["tonescore"];
                charI["liaison"] += obj["liaison"];
            }

            charI["fluency"] = Math.round(charI["fluency"] / cl.normalize.length);
            charI["score"] = Math.round(charI["score"] / cl.normalize.length);
            charI["sensescore"] = Math.round(charI["sensescore"] / cl.normalize.length);
            charI["stressscore"] = Math.round(charI["stressscore"] / cl.normalize.length);
            charI["tonescore"] = Math.round(charI["tonescore"] / cl.normalize.length);

            return new Word(charI);
        } else {
            var charI = this.data.result["details"][i];
            return new Word(charI);
        }
    }

    getCharSize() { return this.data.chars.length; }
    getChar(i) { return new Char(this.data.chars[i]); }

    hasError() {
        return
            (
             typeof this.data.result == 'undefined' ||
             typeof this.data.result.err != 'undefined' ||
             typeof this.data.result.error != 'undefined' ||
             typeof this.data.result.errID != 'undefined'
            );
    }
    getErrorCode() {
        if (typeof this.data.result != 'undefined' &amp;&amp; typeof this.data.result.errID != 'undefined')
            return this.data.result.errID;
        else if (typeof this.data.result.error != 'undefined')
            return this.data.result.error;
    }
}

export default EnSentScore
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK_flash.html">ChiVoxSDK/flash</a></li><li><a href="module-ChiVoxSDK_html5.html">ChiVoxSDK/html5</a></li><li><a href="module-ChiVoxSDK_lib.html">ChiVoxSDK/lib</a></li><li><a href="module-ChiVoxSDK_Paragraph.html">ChiVoxSDK/Paragraph</a></li><li><a href="module-ChiVoxSDK_score.html">ChiVoxSDK/score</a></li></ul><h3>Classes</h3><ul><li><a href="module-ChiVoxSDK_flash.FlashPlayer.html">FlashPlayer</a></li><li><a href="module-ChiVoxSDK_flash.FlashRecorder.html">FlashRecorder</a></li><li><a href="module-ChiVoxSDK_html5.Html5Player.html">Html5Player</a></li><li><a href="module-ChiVoxSDK_html5.Html5Recorder.html">Html5Recorder</a></li><li><a href="module-ChiVoxSDK_html5-VolumeBar.html">VolumeBar</a></li><li><a href="module-ChiVoxSDK_lib-EnScoreMap.html">EnScoreMap</a></li><li><a href="module-ChiVoxSDK_lib-StatusCode.html">StatusCode</a></li><li><a href="module-ChiVoxSDK_Paragraph-Paragraph.html">Paragraph</a></li><li><a href="module-ChiVoxSDK_score-Char.html">Char</a></li><li><a href="module-ChiVoxSDK_score-CnSentScore.html">CnSentScore</a></li><li><a href="module-ChiVoxSDK_score-CnWordScore.html">CnWordScore</a></li><li><a href="module-ChiVoxSDK_score-EnSentRec.html">EnSentRec</a></li><li><a href="module-ChiVoxSDK_score-EnSentScore.html">EnSentScore</a></li><li><a href="module-ChiVoxSDK_score-EnWordScore.html">EnWordScore</a></li><li><a href="module-ChiVoxSDK_score-Phone.html">Phone</a></li><li><a href="module-ChiVoxSDK_score-Word.html">Word</a></li><li><a href="module-ChiVoxSDK-ChiVoxSDK.html">ChiVoxSDK</a></li><li><a href="module-ChiVoxSDK-ControlPanel.html">ControlPanel</a></li><li><a href="module-ChiVoxSDK-Dialog.html">Dialog</a></li><li><a href="module-ChiVoxSDK-PlayerBuilder.html">PlayerBuilder</a></li><li><a href="module-ChiVoxSDK-ProgressBar.html">ProgressBar</a></li><li><a href="module-ChiVoxSDK-RecorderBuilder.html">RecorderBuilder</a></li></ul><h3>Namespaces</h3><ul><li><a href="public.html">public</a></li><li><a href="Utils.html">Utils</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Default_ChiVoxPlayer_Options">Default_ChiVoxPlayer_Options</a></li><li><a href="global.html#Default_ChiVoxRecorder_Options">Default_ChiVoxRecorder_Options</a></li><li><a href="global.html#Default_ChiVoxSDK_Options">Default_ChiVoxSDK_Options</a></li><li><a href="global.html#Default_Paragraph_Options">Default_Paragraph_Options</a></li><li><a href="global.html#get_sig">get_sig</a></li><li><a href="global.html#tts">tts</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Sep 21 2017 16:38:41 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
